package Service;

import java.awt.SystemColor;
import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginService extends HttpServlet{
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("接收到Get请求后会执行的方法!");
		//设置请求对象的数据编码格式
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		//网络数据传输，数据要么是文本字符串，要么是二进制格式的字符串
		String username = req.getParameter("username");//获取账号
		String password = req.getParameter("password");//获取密码
		if("admin".equals(username) && req.equals(password)) {
			req.getRequestDispatcher("index.html").forward(req,resp);
		}else {
			resp.sendRedirect("register.html");
		}
		//重定向:给客户端一个新的地址，客户端再次访问
		//req.getRedirect("index.html");
		
		
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("接收到Post请求后会执行的方法!");
		
	}
	
}
